#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define F first
#define S second
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=2e5+10;
string s[N];
ll b[N][6];
ll a[6][50];
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=n ;i++)
	{
		int sum=0;
		for(int j=0;j<s[i].size();j++)
		{
			sum+=(s[i][j]-'0');
			b[i][j+1]=sum;
		}
		a[s[i].size()][sum]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int len=2;len<=10;len+=2)
		{
			if(len<=s[i].size()) continue;
			if(len/2>s[i].size()) break;
			
		    int num = b[i][s[i].size()]-b[i][len/2] ;
		    ans=ans+ a[len-s[i].size()][max(b[i][len/2]-num,0ll)];
		    
		    int cnt = b[i][s[i].size()-len/2];
		    if(s[i].size()!=len/2) ans=ans + a[len-s[i].size()][max(b[i][s[i].size()]-2*cnt,0ll)];
		}
	}
	cout<<ans<<'\n';
}
int main()
{
	IOS;
	int T=1;
//	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

